import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'Index',
        component: () => import(/* webpackChunkName: "index" */ '../views/compass/index.vue'),
        redirect: '/newConnection',
        children: [
            {
                path: '/save',
                name: 'Save',
                // route level code-splitting
                // this generates a separate chunk (about.[hash].js) for this route
                // which is lazy-loaded when the route is visited.
                component: () => import(/* webpackChunkName: "save" */ '../views/compass/save/index.vue')
            },
            {
                path: '/recent',
                name: 'Recent',
                // route level code-splitting
                // this generates a separate chunk (about.[hash].js) for this route
                // which is lazy-loaded when the route is visited.
                component: () => import(/* webpackChunkName: "recent" */ '../views/compass/recent/index.vue')
            },
            {
                path: '/newConnection',
                name: 'NewConnection',
                // route level code-splitting
                // this generates a separate chunk (about.[hash].js) for this route
                // which is lazy-loaded when the route is visited.
                component: () => import(/* webpackChunkName: "newConnection" */ '../views/compass/newConnection/index.vue')
            }
        ]
    },
    {
        path: '/connection',
        name: 'Connection',
        redirect: '/databases',
        component: () => import(/* webpackChunkName: "newConnection" */ '../views/connection/index.vue'),
        children: [
            {
                path: '/databases',
                name: 'Databases',
                component: () => import(/* webpackChunkName: "Databases" */ '../views/connection/databases/index.vue')
            },
            {
                path: '/documents',
                name: 'Documents',
                component: () => import(/* webpackChunkName: "Documents" */ '../views/connection/documents/index.vue')
            },
            {
                path: '/collections',
                name: 'Collections',
                component: () => import(/* webpackChunkName: "Collections" */ '../views/connection/collections/index.vue')
            }
        ]
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(err => err)
}

export default router
